import subprocess

template = """
[ssm]
public_1 ansible_connection=aws_ssm ansible_aws_ssm_instance_id=%s ansible_aws_ssm_bucket_name=bradley-chatha ansible_aws_ssm_region=eu-west-2 ansible_aws_ssm_plugin=/usr/bin/session-manager-plugin
private_1 ansible_connection=aws_ssm ansible_aws_ssm_instance_id=%s ansible_aws_ssm_bucket_name=bradley-chatha ansible_aws_ssm_region=eu-west-2 ansible_aws_ssm_plugin=/usr/bin/session-manager-plugin
private_2 ansible_connection=aws_ssm ansible_aws_ssm_instance_id=%s ansible_aws_ssm_bucket_name=bradley-chatha ansible_aws_ssm_region=eu-west-2 ansible_aws_ssm_plugin=/usr/bin/session-manager-plugin
local ansible_connection=local
"""
public_1_id = subprocess.check_output(args=["terraform", "output", "-raw", "public_1_instance_id"]).decode("UTF-8")
private_1_id = subprocess.check_output(args=["terraform", "output", "-raw", "private_1_instance_id"]).decode("UTF-8")
private_2_id = subprocess.check_output(args=["terraform", "output", "-raw", "private_2_instance_id"]).decode("UTF-8")

with open("hosts", "w") as f:
    f.write(template % (public_1_id, private_1_id, private_2_id))